package com.emagic.manage.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import com.emagic.manage.LifeApplication;
import com.emagic.manage.common.preference.UserSharedPreference;
import com.emagic.manage.data.utils.GainPointsQueue;
import com.emagic.manage.modules.loginmodule.activity.LoginActivity;

public class TokenFailureReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context, "登录失效，请重新登录", Toast.LENGTH_SHORT).show();

        UserSharedPreference preference = UserSharedPreference.getInstance(context);
        if (preference != null) {
            preference.clear();
        }
        GainPointsQueue queue = GainPointsQueue.getDefault();
        if (queue != null) {
            queue.mainActivityUnInit();
        }
        LifeApplication.getInstance().release();

        Intent intentToLaunch = LoginActivity.getCallingIntent(context, "");
        intentToLaunch.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intentToLaunch);
    }
}
